document.addEventListener('plusready',function(){
	$.ajax({
		type:"get",
		url:apiRoot+"?m=home&c=article&a=dose",
//		dataType:'json',
		success : function(data){
			plus.storage.setItem('jlzh',data);
			var newl = $.parseJSON(data);
			//汉
			var str1 = '';
			$.each(newl['han']['jil'], function(k,v) {
				$('.shi').text(v.fieldsname[0]); 
				$('.shi').attr('data-id',v.fields);
				$('.shi').attr('data-type','han');
				str1 += '<li class="mui-table-view-cell fies" data-id="'+v.fields+'" data-type="han">'+v.fieldsname+'</li>';
			});
			$('.han').html(str1);
			//宋
			var str2 = '';
			$.each(newl['song']['jil'], function(k,v) {
				str2 += '<li class="mui-table-view-cell fies" data-id="'+v.fields+'" data-type="song">'+v.fieldsname+'</li>';
			});
			$('.song').html(str2);
			//点击
			$('.fies').on('click',function(){
				var a = $(this).attr('data-id');
				var t = $(this).attr('data-type');
				$(".danwei-list").hide();
				$('.shi').text($(this).text());
				$('.shi').attr('data-id',$(this).attr('data-id'));
				$('.shi').attr('data-type',$(this).attr('data-type'));
				info = newl[t][a].split('=');
				$('.ke').text(info[0]);
				var z = $('.qian').val();
				if(!z.match(p3)){
					$('.qian').val('');
					$('.zong').val('');
					toast('数据有误！');return;
				}
				$('.zong').val(parseFloat(z)*parseFloat(info[1]));
			})
		},
		error :function(e){
			var dat = plus.storage.getItem('jlzh');
			var new2 = $.parseJSON(dat);
			//汉
			var str3 = '';
			$.each(new2['han']['jil'], function(k,v) {
				str3 += '<li class="mui-table-view-cell fies" data-id="'+v.fields+'" data-type="han">'+v.fieldsname+'</li>';
			});
			$('.han').html(str3);
			//宋
			var str4 = '';
			$.each(new2['song']['jil'], function(k,v) {
				str4 += '<li class="mui-table-view-cell fies" data-id="'+v.fields+'" data-type="song">'+v.fieldsname+'</li>';
			});
			$('.song').html(str4);
		}
	});
	//选择“汉”，“宋”事件
	$('input[name=radio1]').change(function(){
		console.log($(this).attr('value'));
		if($(this).attr('value') == 1){
			//汉
			$('.han').show();
			$('.song').hide();
			$('.qian').val('');
			$('.zong').val('');
			$(".danwei-list").hide();
		}else{
			//宋
			$('.han').hide();
			$('.song').show();
			$('.qian').val('');
			$('.zong').val('');
			$(".danwei-list").hide();
		}
	})
	//输入数字事件
	$('.qian').keyup(function(){
		console.log($('.qian').val());
		var radi = $('input[name=radio1]').val();
		console.log($('input[name=radio1]').val());
		var newd = plus.storage.getItem('jlzh');
		var newl = $.parseJSON(newd);
		var a = $('.shi').attr('data-id');
		var t = $('.shi').attr('data-type');
		console.log(a+" "+t);
		if(a && t){
			info = newl[t][a].split('=');
			$('.ke').text(info[0]);
			var z = $('.qian').val();
			if(!z.match(p3)){
				$('.qian').val('');
				$('.zong').val('');
				toast('数据有误！');return;
			}
			$('.zong').val(parseFloat(z)*parseFloat(info[1]));
		}else{
			console.log(123);
			
		}
		
	})
	//剂量规则
	$.ajax({
		type:"get",
		url:apiRoot+"/home/medicinal/doseRule/aid/7",
		success :function(data){ 
			console.log(data);
			if(data){
				$('.counter-text').html(data);
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
		}
	});
},false)

